﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace game
{
    public abstract class PostProcessEffect
    {
        public PostProcessEffectType Type { get; protected set; }
        public abstract void Draw(GameTime gameTime, List<GameObject> objects);

        protected GraphicsDevice device ;
        protected Scene scene;

        public PostProcessEffect(Scene scene)
        {
            this.scene = scene;
            this.device = ShooterGame.Instance.GraphicsDevice;
        }

        protected void DrawFullscreenQuad(Texture2D texture, RenderTarget2D renderTarget,
                                Effect effect)
        {
            device.SetRenderTarget(0, renderTarget);

            DrawFullscreenQuad(texture,
                               renderTarget.Width, renderTarget.Height,
                               effect);

            device.SetRenderTarget(0, null);
        }


        protected void DrawFullscreenQuad(Texture2D texture, int width, int height,
                                Effect effect)
        {
            ShooterGame.Instance.SpriteBatch.Begin(SpriteBlendMode.None,
                              SpriteSortMode.Immediate,
                              SaveStateMode.None);


            effect.Begin();
            effect.CurrentTechnique.Passes[0].Begin();

            ShooterGame.Instance.SpriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            ShooterGame.Instance.SpriteBatch.End();

            effect.CurrentTechnique.Passes[0].End();
            effect.End();
        }

        protected void DrawFullscreenQuad(Texture2D texture, SpriteBlendMode blendMode)
        {
            ShooterGame.Instance.SpriteBatch.Begin(blendMode,
                SpriteSortMode.Immediate, SaveStateMode.None);

            ShooterGame.Instance.SpriteBatch.Draw(texture,
                new Rectangle(0, 0,
                    device.PresentationParameters.BackBufferWidth,
                    device.PresentationParameters.BackBufferHeight),
                    Color.White);
            ShooterGame.Instance.SpriteBatch.End();
        }
    }
}
